package com.lemon.smartsafety.rayeye;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;
import com.lemon.smartsafety.R;
import com.lemon.smartsafety.rayeye.entity.BundleKey;
import com.lemon.smartsafetynew.ui.fragment.base.BaseFragment;
import com.lemon.smartsafety.ui.widget.ViewPagerEnableScroll;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Cooliean on 16/4/16.
 */
public class FaultFragment extends BaseFragment {

    private String[]            mTitles    = {"未确认", "物业已报修", "忽略", "维修中", "已屏蔽", "已维修"};
    //0未确认 1物业已报修  2 忽略   3 维修中 4已屏蔽  5已维修
    private ArrayList<Fragment> mFragments = new ArrayList<>();


    @Bind(R.id.tl_com)
    SlidingTabLayout      mTabs;
    @Bind(R.id.viewPager)
    ViewPagerEnableScroll viewPager;


    FragmentStatePagerAdapter mAdapter;

    private int mBuildingId = 0;
    private String mCompanyCode = "";


    public static FaultFragment newInstance(String company_code, int buildingId) {
        Bundle bundle = new Bundle();
        bundle.putInt(BundleKey.BUILDING_ID, buildingId);
        bundle.putString(BundleKey.COMPANY_CODE, company_code);
        FaultFragment fragment = new FaultFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void getBaseArguments() {
        if (getArguments() != null) {
            mBuildingId = getArguments().getInt(BundleKey.BUILDING_ID, 0);
            mCompanyCode = getArguments().getString(BundleKey.COMPANY_CODE,"");
        }
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_fault_all_detail_list;
    }

    @Override
    protected void initViews() {
        initPageView();
    }

    private void initPageView() {
        mAdapter = new FragmentStatePagerAdapter(getFragmentManager()) {

            @Override
            public int getCount() {
                return mTitles.length;
            }

            @Override
            public Fragment getItem(int position) {
                return FaultListFragment.newInstance(mCompanyCode,mBuildingId, position);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return mTitles[position];
            }
        };
        viewPager.setAdapter(mAdapter);

        mTabs.setViewPager(viewPager, mTitles);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }
}
